#ifndef _OPENGLAPPFRAMEWORK_PLUGIN_H_
#define _OPENGLAPPFRAMEWORK_PLUGIN_H_

#include <string>
#include "json/inc/json.hpp"

enum class PlugInType {
    Mesh, Material, ParallelLight, Camera, Actions, Instancing, LOD,
    Illegal
};

PlugInType string2PlugInType(const std::string& str);

class GameObject;
class Shader;
class PlugIn {
public:
    PlugIn(const std::string& name, PlugInType type);
    virtual ~PlugIn();

    /**
     * @brief 根据配置文件的内容，创建PlugIn子类的实例（不load数据）
     * @return 失败时返回nullptr
     */
    static PlugIn* CreatePlugInByJson(const std::string& name, const nlohmann::json& js);

    // 设置PlugIn所属的GameObject
    void setGameObject(GameObject* obj);
    void setEnable(bool enable);
    const std::string& name() const;
    PlugInType type() const;
    bool isEnable() const;

    // 读取配置文件的内容
    virtual int setConfigData(const nlohmann::json& data)=0; // 不同类型的Plugin独有的配置
    virtual int init()=0;
    virtual void destroy()=0;
    virtual void routine() {}
    virtual void uploadShaderData(Shader* ) {}

    // virtual void uploadConstShaderData();
    // virtual void uploadFrameShaderData();
    // virtual void uploadEntityShaderData();

protected:
    std::string m_name;
    const PlugInType m_plugin_type;
    bool m_is_enable;
    GameObject* m_obj;
};

#endif//_OPENGLAPPFRAMEWORK_PLUGIN_H_
